#ifndef _LCD_H_
#define _LCD_H_

#include <stdint.h>

/**
 * @def USE_HORIZONTAL
 * @brief Orientation setting for the LCD screen.
 *
 * 0 or 1 = Portrait mode  
 * 2 or 3 = Landscape mode
 */
#define USE_HORIZONTAL      0

/**
 * @def LCD_W
 * @def LCD_H
 * @brief Width and height of the LCD based on orientation.
 */
#if ((USE_HORIZONTAL==0) || (USE_HORIZONTAL==1))
#define LCD_W 240
#define LCD_H 329
#else
#define LCD_W 320
#define LCD_H 240
#endif

/* Color definitions */
#define LCD_WHITE           0xFFFF
#define LCD_BLACK           0x0000
#define LCD_BLUE            0x001F
#define LCD_BRED            0XF81F
#define LCD_GRED            0XFFE0
#define LCD_GBLUE           0X07FF
#define LCD_RED             0xF800
#define LCD_MAGENTA         0xF81F
#define LCD_GREEN           0x07E0
#define LCD_CYAN            0x7FFF
#define LCD_YELLOW          0xFFE0
#define LCD_BROWN           0XBC40
#define LCD_BRRED           0XFC07
#define LCD_GRAY            0X8430
#define LCD_DARKBLUE        0X01CF
#define LCD_LIGHTBLUE       0X7D7C
#define LCD_GRAYBLUE        0X5458
#define LCD_LIGHTGREEN      0X841F
#define LCD_LGRAY           0XC618
#define LCD_LGRAYBLUE       0XA651
#define LCD_LBBLUE          0X2B12

/**
 * @brief Initialize the LCD display.
 *
 * This function initializes the hardware interface and configuration settings for the LCD.
 *
 * @return unsigned int Returns 0 on success, or an error code on failure.
 */
unsigned int lcd_init();

/**
 * @brief Deinitialize the LCD display.
 *
 * This function releases resources and powers down the LCD module.
 *
 * @return unsigned int Returns 0 on success, or an error code on failure.
 */
unsigned int lcd_deinit();

/**
 * @brief Fill a rectangular area with a specified color.
 *
 * This function fills the area between (xsta, ysta) and (xend, yend) with the given color.
 *
 * @param xsta Start X coordinate.
 * @param ysta Start Y coordinate.
 * @param xend End X coordinate.
 * @param yend End Y coordinate.
 * @param color The 16-bit color value to fill.
 */
void lcd_fill(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color);

/**
 * @brief Draw a single pixel at the specified coordinates.
 *
 * This function draws a point (single pixel) at position (x, y) with the given color.
 *
 * @param x X coordinate of the point.
 * @param y Y coordinate of the point.
 * @param color The 16-bit color value.
 */
void lcd_draw_point(uint16_t x, uint16_t y, uint16_t color);

/**
 * @brief Draw a line between two points.
 *
 * This function draws a line from (x1, y1) to (x2, y2) with the given color.
 *
 * @param x1 Start X coordinate.
 * @param y1 Start Y coordinate.
 * @param x2 End X coordinate.
 * @param y2 End Y coordinate.
 * @param color The 16-bit color value.
 */
void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);

/**
 * @brief Draw a rectangle outline.
 *
 * This function draws the border of a rectangle from (x1, y1) to (x2, y2) with the given color.
 *
 * @param x1 Top-left X coordinate.
 * @param y1 Top-left Y coordinate.
 * @param x2 Bottom-right X coordinate.
 * @param y2 Bottom-right Y coordinate.
 * @param color The 16-bit color value.
 */
void lcd_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);

/**
 * @brief Draw a circle outline.
 *
 * This function draws the border of a circle centered at (x0, y0) with radius r and given color.
 *
 * @param x0 Center X coordinate.
 * @param y0 Center Y coordinate.
 * @param r Radius of the circle.
 * @param color The 16-bit color value.
 */
void lcd_draw_circle(uint16_t x0, uint16_t y0, uint8_t r, uint16_t color);

/**
 * @brief Display a UTF-8 encoded Chinese string.
 *
 * This function displays a multi-byte Chinese character string at the specified location.
 *
 * @param x Start X coordinate.
 * @param y Start Y coordinate.
 * @param s Pointer to the UTF-8 encoded string.
 * @param fc Foreground color (text color).
 * @param bc Background color.
 * @param sizey Font size (e.g., 12, 16, 24, 32).
 * @param mode 0: non-overlay; 1: overlay (transparent background).
 */
void lcd_show_chinese(uint16_t x, uint16_t y, uint8_t *s, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode);

/**
 * @brief Display a single ASCII character.
 *
 * This function displays a single ASCII character at the specified location.
 *
 * @param x Start X coordinate.
 * @param y Start Y coordinate.
 * @param c ASCII character to display.
 * @param fc Foreground color (text color).
 * @param bc Background color.
 * @param sizey Font size (e.g., 12, 16, 24, 32).
 * @param mode 0: non-overlay; 1: overlay (transparent background).
 */
void lcd_show_char(uint16_t x, uint16_t y, uint8_t c, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode);

/**
 * @brief Display an ASCII string.
 *
 * This function displays a null-terminated ASCII string at the specified location.
 *
 * @param x Start X coordinate.
 * @param y Start Y coordinate.
 * @param p Pointer to the ASCII string.
 * @param fc Foreground color (text color).
 * @param bc Background color.
 * @param sizey Font size (e.g., 16, 24, 32).
 * @param mode 0: non-overlay; 1: overlay (transparent background).
 */
void lcd_show_string(uint16_t x, uint16_t y, const uint8_t *p, uint16_t fc, uint16_t bc, uint8_t sizey, uint8_t mode);

/**
 * @brief Display an integer number.
 *
 * This function displays a 16-bit unsigned integer at the specified location.
 *
 * @param x Start X coordinate.
 * @param y Start Y coordinate.
 * @param num Integer number to display.
 * @param len Number of digits to display.
 * @param fc Foreground color.
 * @param bc Background color.
 * @param sizey Font size (e.g., 16, 24, 32).
 */
void lcd_show_int_num(uint16_t x, uint16_t y, uint16_t num, uint8_t len, uint16_t fc, uint16_t bc, uint8_t sizey);

/**
 * @brief Display a floating-point number with one decimal place.
 *
 * This function displays a float number rounded to one decimal place.
 *
 * @param x Start X coordinate.
 * @param y Start Y coordinate.
 * @param num Float number to display.
 * @param len Total number of characters to display (including decimal point).
 * @param fc Foreground color.
 * @param bc Background color.
 * @param sizey Font size (e.g., 16, 24, 32).
 */
void lcd_show_float_num1(uint16_t x, uint16_t y, float num, uint8_t len, uint16_t fc, uint16_t bc, uint8_t sizey);

/**
 * @brief Display a picture/image.
 *
 * This function displays a raw image starting at (x, y) with specified width and height.
 *
 * @param x Start X coordinate.
 * @param y Start Y coordinate.
 * @param length Image width in pixels.
 * @param width Image height in pixels.
 * @param pic Pointer to the image data array (RGB565 format).
 */
void lcd_show_picture(uint16_t x, uint16_t y, uint16_t length, uint16_t width, const uint8_t *pic);

#endif /* _LCD_H_ */
